package com.hkw.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 退出登入
 */
@WebServlet(name = "OutLoginServlet",urlPatterns = "/outLogin")
public class OutLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //将对应的cookie覆盖，path一致，存活时间设为0
        Cookie cookie = new Cookie("certificate","loginFail");
        cookie.setMaxAge(0);
        cookie.setPath("http://localhost:8080/homework");
        response.addCookie(cookie);
        System.out.println("退出登入");
        response.sendRedirect("index.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
